package com.cqupt.springframework.util;

/**
 * @author Zhy
 * @date 2021/6/19 15:08
 */
public class ClassUtils {

    public static ClassLoader getDefaultClassLoader() {
        ClassLoader classLoader = null;
        try {
            classLoader = Thread.currentThread().getContextClassLoader();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        if (classLoader == null) {
            classLoader = ClassUtils.class.getClassLoader();
        }
        return classLoader;
    }

    /**
     * Check whether the specified class is a CGLIB-generated class.
     * @param clazz the class to check
     */
    public static boolean isCglibProxyClass(Class<?> clazz) {
        return (clazz != null && isCglibProxyClassName(clazz.getName()));
    }


    /**
     * Check whether the specified class name is a CGLIB-generated class.
     * @param name the class name to check
     */
    private static boolean isCglibProxyClassName(String name) {
        return (name != null && name.contains("$$"));
    }
}
